Our project

We decided to do central Colombia, basically because it is where the capital is.

We built a model for the number of confirmed cases using all the others covariates (plus some we created) and we estimated the predictive accuracy of our selected model.

We decided to consider as central Colombia the following departments/districts: Bogotà DC, Boyacá, Tolima, Cundinamarca, Meta, Quindío, Valle del Cauca, Risaralda, Celdas, Boyacá, Antioquia, Santander, Casanare.

Loading the dataset

This dataset is missing completely the department Valle del Cauca!

##   ID de caso Fecha de diagnóstico Ciudad de ubicación Departamento o Distrito
## 1          1           06/03/2020         Bogotá D.C.             Bogotá D.C.
## 3          3           09/03/2020            Medellín               Antioquia
## 4          4           11/03/2020            Medellín               Antioquia
## 5          5           11/03/2020            Medellín               Antioquia
## 6          6           11/03/2020              Itagüí               Antioquia
##     Atención Edad Sexo        Tipo País de procedencia
## 1 Recuperado   19    F   Importado              Italia
## 3 Recuperado   50    F   Importado              España
## 4 Recuperado   55    M Relacionado                 Nan
## 5 Recuperado   25    M Relacionado                 Nan
## 6 Recuperado   27    F Relacionado                 Nan

Description of variables

  • ID de caso: ID of the confirmed case.

  • Fecha de diagnóstico: Date in which the disease was diagnosed.

  • Ciudad de ubicación: City where the case was diagnosed.

  • Departamento o Distrito: Department or district where the city belongs to.

  • Atención: Situation of the patient: recovered, at home, at the hospital, at the ICU or deceased.

  • Edad: Age of the confirmed case.

  • Sexo: Sex of the confirmed case.

  • Tipo: How the person got infected: in Colombia, abroad or unknown.

  • País de procedencia: Country of origin if the person got infected abroad.

Map

Here we can see our selected cities. The color of the pins is related with the number of cases: if they are less than \(10\) the color is “green”, if they are less than \(100\) the color is “orange”, otherwise it is “red”.

Preprocessing

We had to clean the dataset:

  • We transformed the Fecha de diagnóstico variable into a Date type variable,

  • we fixed the variable Id de caso (since we removed some departments, so some lines, the numbers weren’t consecutive),

  • we created a variable Grupo de edad,

  • we cleaned the column País de procedencia (replaced cities with the country) and created the variable Continente de procedencia (as the first is too fragmented we thought to consider the continents).

##    ID de caso Fecha de diagnóstico Ciudad de ubicación Departamento o Distrito
## 1           1           2020-03-06         Bogotá D.C.             Bogotá D.C.
## 2           2           2020-03-09            Medellín               Antioquia
## 3           3           2020-03-11            Medellín               Antioquia
## 4           4           2020-03-11            Medellín               Antioquia
## 5           5           2020-03-11              Itagüí               Antioquia
## 6           6           2020-03-11         Bogotá D.C.             Bogotá D.C.
## 7           7           2020-03-11         Bogotá D.C.             Bogotá D.C.
## 8           8           2020-03-12         Bogotá D.C.             Bogotá D.C.
## 9           9           2020-03-12         Bogotá D.C.             Bogotá D.C.
## 10         10           2020-03-13       Villavicencio                    Meta
##      Atención Edad Sexo        Tipo País de procedencia Grupo de edad
## 1  Recuperado   19    F   Importado              Italia         19_30
## 2  Recuperado   50    F   Importado              España         46_60
## 3  Recuperado   55    M Relacionado                 Nan         46_60
## 4  Recuperado   25    M Relacionado                 Nan         19_30
## 5  Recuperado   27    F Relacionado                 Nan         19_30
## 6  Recuperado   22    F   Importado              España         19_30
## 7  Recuperado   28    F   Importado              España         19_30
## 8  Recuperado   36    F   Importado              España         31_45
## 9  Recuperado   42    F   Importado              España         31_45
## 10 Recuperado   30    F   Importado              España         19_30

New dataset I

##          Date Elapsed time New cases/day Cumulative cases
## 1  2020-03-06            0             1                1
## 2  2020-03-09            3             1                2
## 3  2020-03-11            5             5                7
## 4  2020-03-12            6             2                9
## 5  2020-03-13            7             3               12
## 6  2020-03-14            8            14               26
## 7  2020-03-15            9            13               39
## 8  2020-03-16           10             8               47
## 9  2020-03-17           11            13               60
## 10 2020-03-18           12             9               69

New dataset II

##          Date Elapsed time Department Department ID New cases/day
## 1  2020-03-09            3  Antioquia             1             1
## 2  2020-03-11            5  Antioquia             1             3
## 3  2020-03-14            8  Antioquia             1             3
## 4  2020-03-15            9  Antioquia             1             1
## 5  2020-03-19           13  Antioquia             1             3
## 6  2020-03-20           14  Antioquia             1            11
## 7  2020-03-21           15  Antioquia             1             3
## 8  2020-03-22           16  Antioquia             1             5
## 9  2020-03-23           17  Antioquia             1            22
## 10 2020-03-25           19  Antioquia             1             8
##    Cumulative cases/Department Mean age
## 1                            1 50.00000
## 2                            4 35.66667
## 3                            7 30.00000
## 4                            8 55.00000
## 5                           11 52.33333
## 6                           22 39.81818
## 7                           25 31.00000
## 8                           30 45.40000
## 9                           52 36.45455
## 10                          60 29.75000

Exploring the dataset

Scattered infos about pandemic in Colombia (https://en.wikipedia.org/wiki/COVID-19_pandemic_in_Colombia):

  • the quarantine started on the 20th of March, since our data are from 6th of March to 2nd of April, it is very likeliy that quarantine effects are not witnessed in our data.

  • on March the 26th there was a damage in the machine that prepared the samples for processing and subsequent diagnosis of COVID-19, which affected the speed at which results were being produced. This could explain the very low number of confirmed cases.



## List of 3
##  $ axis.line       :List of 6
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ panel.background: list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ panel.grid      : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi FALSE
##  - attr(*, "validate")= logi TRUE

The previous plot represents the daily incidence of the desease across all the departments we are taking into account.

Frequency of cases across Departments


The major number of cases are in the capital Bogotà.

Cumulative number of confirmed cases


Here the growth seems exponential (and this is consistent with the fact that we are studying the early stages of the outbreak).

Variables plots

Age-Sex plot


There isn’t much difference between the sexes among the different group of ages.

Tipo plot

I think that en estudio means that it is not clear while the case is imported or not, however it seems like there are more imported cases, we can count them:

## # A tibble: 3 x 3
##   Tipo        `Total number` Percentage
##   <chr>                <int> <chr>     
## 1 Relacionado           8570 12%       
## 2 Importado              687 1%        
## 3 En Estudio           60406 87%

The majority of the cases in the country are people that got infected inside Colombia. Then, people that contracted the disease abroad came mainly from Europe, followed by North America and Central America.

Correlation between the categorical variables

We used Cramer’s V to calculate the correlation between our categorical variables.


The frequentist approach

Train/test split

We splitted the data so to leave out the last three points for prediction, because we have few points and because in this models it has no sense to predict a week, because the situation changes really fast.

GLM

Poisson

Poisson with Elapsed time as predictor for Cumulative cases


## [1] "Estimated overdispersion 126.060786858437"
## [1] "RMSE: 1760.50922940986"
## [1] "AIC: 21915.0291925917"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 20716.39"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.158730158730159"

Prediction interval for test set


Poisson with Elapsed time as predictor for New cases/day


## [1] "DO OVERDISPERSION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
## [1] "RMSE: 58886.3428634314"
## [1] "AIC: 7291.77457395168"
## [1] "Null deviance:  64369.08"   "Residual deviance: 6442.53"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0"

Prediction interval for test set


Poisson with Elapsed time plus Elapsed time^2 as predictor for New cases/day


## [1] "Estimated overdispersion 292693.098510483"
## [1] "RMSE: 739.356869793342"
## [1] "AIC: 7291.99073697742"
## [1] "Null deviance:  64369.08"   "Residual deviance: 6440.75"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0"

Prediction interval for test set


Poisson with Elapsed time plus Sex for Cumulative cases


## [1] "RMSE: 3892.80826581986"
## [1] "AIC: 20887.674847589"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 19687.03"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.166666666666667"

Prediction interval for test set


Poisson with Elapsed time plus Sex as predictor for New cases/day


## [1] "Estimated overdispersion 314252.241298368"
## [1] "RMSE: 1810.41842007254"
## [1] "AIC: 4079.27639935841"
## [1] "Null deviance:  64369.08"   "Residual deviance: 3228.03"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0"

Prediction interval for test set


Poisson with Elapsed time plus Age group for Cumulative cases


## [1] "Estimated overdispersion 439618.33736315"
## [1] "RMSE: 3249.31716470375"
## [1] "AIC: 20650.0253613547"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 19441.38"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.126984126984127"

Prediction interval for test set


Poisson with Elapsed time plus Age group as predictor for New cases/day


## [1] "Estimated overdispersion 315886.748769649"
## [1] "RMSE: 1948.8032473443"
## [1] "AIC: 3845.15073713936"
## [1] "Null deviance:  64369.08"   "Residual deviance: 2985.91"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0"

Prediction interval for test set


Poisson with Elapsed time plus Department for Cumulative cases


## [1] "Estimated overdispersion 463825.016009504"
## [1] "RMSE: 3328.87135693358"
## [1] "AIC: 19275.3910967978"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 18054.75"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.0793650793650794"

Prediction interval for test set


Poisson with Elapsed time plus Department as predictor for New cases/day


## [1] "Estimated overdispersion 323812.380263625"
## [1] "RMSE: 1447.54763192187"
## [1] "AIC: 2989.46506265985"
## [1] "Null deviance:  64369.08"   "Residual deviance: 2118.22"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0"

Prediction interval for test set


Poisson with Elapsed time, Age and Departments as predictors for Cumulative cases


## [1] "Estimated overdispersion 542039.960916532"
## [1] "RMSE: 8243.70282563776"
## [1] "AIC: 18085.2709276108"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 16854.63"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.119047619047619"

Prediction interval for test set


Poisson with Elapsed time, Age and Departments as predictors for New cases/day


## [1] "Estimated overdispersion 6719176.07903642"
## [1] "RMSE: 1225.26041309972"
## [1] "AIC: 2860.38819023372"
## [1] "Null deviance:  64369.08"   "Residual deviance: 1979.14"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.436507936507937"

Prediction interval for test set

Work in progress.. the plot came out very strange, if we don’t plan to include it in the presentation it is not worth spending time in it.. also because in the previous plot the interval is strangely visible!

Poisson with Elapsed time, Elapsed time^2, Age and Departments as predictors for Cumulative cases


## [1] "Estimated overdispersion 1238590.22360691"
## [1] "RMSE: 8441.28307878747"
## [1] "AIC: 8781.84768119021"
## [1] "Null deviance:  1740689.09" "Residual deviance: 7549.2"

Predictive accuracy

## [1] "Frequency of coverage: 0.0416666666666667"

Prediction interval for test set

Same obs as before.. there is something strange in the function when the model overestimates the predictions

Poisson with Elapsed time, Elapsed time^2, Age and Departments as predictors for New cases/day


## [1] "Estimated overdispersion 14073361.5599128"
## [1] "RMSE: 3072.65556331751"
## [1] "AIC: 2225.47391742673"
## [1] "Null deviance:  64369.08"   "Residual deviance: 1342.23"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.46031746031746"

Prediction interval for test set

Same as before.

Summary table - Poisson models for Cumulative cases

Model AIC RMSE
Cumulative cases ~ Elapsed time 21915.0291925917 1760.50922940986
Cumulative cases ~ Elapsed time + Elapsed time^2 12062.7254007421 6940.37335779742
Cumulative cases ~ Elapsed time + Sex 20887.674847589 3892.80826581986
Cumulative cases ~ Elapsed time + Age group 20650.0253613547 3249.31716470375
Cumulative cases ~ Elapsed time + Department 19275.3910967978 3328.87135693358
Cumulative cases ~ Elapsed time + Department + Age group 18085.2709276108 8243.70282563776
Cumulative cases ~ Elapsed time + Elapsed time^2 + Department + Age group 8781.84768119021 8441.28307878747

Summary table - Poisson models for New cases/day

Model AIC RMSE
New cases/day ~ Elapsed time 7291.77457395168 58886.3428634314
New cases/day ~ Elapsed time + Age group + Department 2989.46506265985 1447.54763192187

Autocorrelation to compare Poisson models

We generated 1000 samples from each of the four Poisson models and calculated the autocorrelation and compared against the autocorrelation of our original sample.

Autocorrelation for the models when the response variable is Cumulative Cases


Autocorrelation for the models when the response variable is New cases/day


ANOVA to compare the Poisson models

## Analysis of Deviance Table
## 
## Model 1: `Cumulative cases` ~ `Elapsed time`
## Model 2: `Cumulative cases` ~ `Elapsed time` + I(`Elapsed time`^2)
## Model 3: `Cumulative cases` ~ `Elapsed time` + Sexo_M
## Model 4: `Cumulative cases` ~ `Elapsed time` + `Grupo de edad_19_30` + 
##     `Grupo de edad_31_45` + `Grupo de edad_46_60` + `Grupo de edad_60_75` + 
##     `Grupo de edad_76+`
## Model 5: `Cumulative cases` ~ `Elapsed time` + `Departamento o Distrito_Bogotá D.C.` + 
##     `Departamento o Distrito_Boyacá` + `Departamento o Distrito_Caldas` + 
##     `Departamento o Distrito_Casanare` + `Departamento o Distrito_Cauca` + 
##     `Departamento o Distrito_Cundinamarca` + `Departamento o Distrito_Meta` + 
##     `Departamento o Distrito_Quindío` + `Departamento o Distrito_Risaralda` + 
##     `Departamento o Distrito_Santander` + `Departamento o Distrito_Tolima`
## Model 6: `Cumulative cases` ~ `Elapsed time` + `Grupo de edad_19_30` + 
##     `Grupo de edad_31_45` + `Grupo de edad_46_60` + `Grupo de edad_60_75` + 
##     `Grupo de edad_76+` + `Departamento o Distrito_Bogotá D.C.` + 
##     `Departamento o Distrito_Boyacá` + `Departamento o Distrito_Caldas` + 
##     `Departamento o Distrito_Casanare` + `Departamento o Distrito_Cauca` + 
##     `Departamento o Distrito_Cundinamarca` + `Departamento o Distrito_Meta` + 
##     `Departamento o Distrito_Quindío` + `Departamento o Distrito_Risaralda` + 
##     `Departamento o Distrito_Santander` + `Departamento o Distrito_Tolima`
## Model 7: `Cumulative cases` ~ `Elapsed time` + I(`Elapsed time`^2) + `Grupo de edad_19_30` + 
##     `Grupo de edad_31_45` + `Grupo de edad_46_60` + `Grupo de edad_60_75` + 
##     `Grupo de edad_76+` + `Departamento o Distrito_Bogotá D.C.` + 
##     `Departamento o Distrito_Boyacá` + `Departamento o Distrito_Caldas` + 
##     `Departamento o Distrito_Casanare` + `Departamento o Distrito_Cauca` + 
##     `Departamento o Distrito_Cundinamarca` + `Departamento o Distrito_Meta` + 
##     `Departamento o Distrito_Quindío` + `Departamento o Distrito_Risaralda` + 
##     `Departamento o Distrito_Santander` + `Departamento o Distrito_Tolima`
##   Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
## 1       118    20716.4                          
## 2       117    10862.1  1   9854.3 < 2.2e-16 ***
## 3       117    19687.0  0  -8824.9              
## 4       113    19441.4  4    245.6 < 2.2e-16 ***
## 5       107    18054.7  6   1386.6 < 2.2e-16 ***
## 6       102    16854.6  5   1200.1 < 2.2e-16 ***
## 7       101     7549.2  1   9305.4 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Quasi-Poisson

Quasi Poisson with Elapsed time as predictor for Cumulative cases


## [1] "Estimated overdispersion 15728.0601174826"
## [1] "RMSE: 1760.50922940986"
## [1] "AIC: NA"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 20716.39"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.841269841269841"

Quasi Poisson with Elapsed time as predictors for New cases/day


## [1] "Estimated overdispersion 8958055.49491902"
## [1] "RMSE: 753.966239397641"
## [1] "AIC: NA"
## [1] "Null deviance:  64369.08"   "Residual deviance: 6442.53"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.183333333333333"

Prediction interval for test set


quite horrible.. maybe unnecessary since the previous plot is good!

Quasi Poisson with Elapsed time and Age as predictor for Cumulative cases


## [1] "Estimated overdispersion 21853.7140901657"
## [1] "RMSE: 3249.31716470375"
## [1] "AIC: NA"
## [1] "Null deviance:  1740689.09"  "Residual deviance: 19441.38"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.865079365079365"

Prediction interval for test set

Almost like the previous one.. but maybe even here it is not necessary

Summary table - Quasi Poisson models for Cumulative cases

Model RMSE
Cumulative cases ~ Elapsed time 1760.50922940986
Cumulative cases ~ Elapsed time + Age group 3249.31716470375

Summary table - Quasi Poisson models for New cases/day

Model RMSE
New cases/day ~ Elapsed time 753.9662

Negative Binomial

Negative Binomial with Elapsed time as predictor


## [1] "Estimated overdispersion 177.301055416919"
## [1] "RMSE: 1765.66109000166"
## [1] "AIC: 21911.1770461798"
## [1] "Null deviance:  1738722.15"  "Residual deviance: 20710.41"

Predictive accuracy of the Negative Binomial model

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.158730158730159"

Prediction interval for test set


Negative Binomial with Elapsed time plus Age as predictors for Cumulative cases


## [1] "COMPUTE OVERDISPERSION!!!!!!!!!!!!!!!!!!!!!!!"
## [1] "RMSE: 3253.44941446475"
## [1] "AIC: 20645.2695885301"
## [1] "Null deviance:  1738975.56"  "Residual deviance: 19434.52"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.119047619047619"

Prediction interval for test set


Negative Binomial with Elapsed time plus Department as predictors for Cumulative cases


## [1] "COMPUTE OVERDISPERSION!!!!!!!!!!!!!!!!!"
## [1] "RMSE: 3335.37126363787"
## [1] "AIC: 19270.2478115559"
## [1] "Null deviance:  1739087.22" "Residual deviance: 18047.5"

Predictive accuracy

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.0714285714285714"

Prediction interval for test set


Negative Binomial with Elapsed time, Age and Departments as pedictors


## [1] "Estimated overdispersion 187.463666129657"
## [1] "RMSE: 8253.89918445986"
## [1] "AIC: 18080.4893928766"
## [1] "Null deviance:  1739076.35"  "Residual deviance: 16847.74"

Predictive accuracy of the Negative Binomial model

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.119047619047619"

Prediction interval for test set


Negative Binomial with Elapsed time, Age and Departments as pedictors for New cases/day


## [1] "Estimated overdispersion 1.62538490690911"
## [1] "RMSE: 1379.56664915407"
## [1] "AIC: 1435.14403991019"
## [1] "Null deviance:  1416.29"   "Residual deviance: 146.46"

Predictive accuracy of the NB model for New cases/day

Predicting with a \(95\%\) confidence interval

## [1] "Frequency of coverage: 0.944444444444444"

Prediction interval for test set


One word.. horrible!

Summary table - Negative Binomial models for Cumulative cases

Model AIC RMSE
Cumulative cases ~ Elapsed time 21911.1770461798 1765.66109000166
Cumulative cases ~ Elapsed time + Age group 20645.2695885301 3253.44941446475
Cumulative cases ~ Elapsed time + Department 19270.2478115559 3335.37126363787
Cumulative cases ~ Elapsed time + Department + Age group 18080.4893928766 8253.89918445986

Summary table - Negative Binomial models for New cases/day

Model AIC RMSE
New cases/day ~ Elapsed time + Age group + Department 1435.144 1379.567

Autocorrelation to compare Negative Binomial models

We generated 1000 samples from each of the four Negative Binomial models and calculated the autocorrelation and compared against the autocorrelation of our original sample.

Autocorrelation for the models when the response variable is Cumulative Cases


Autocorrelation for the model when the response variable is New cases/day


Applying ANOVA to compare the negative binomial models

## Likelihood ratio tests of Negative Binomial Models
## 
## Response: Cumulative cases
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Model
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Elapsed time
## 2                                                                                                                                                                                                                                                                                                                                                                                                                         `Elapsed time` + `Grupo de edad_19_30` + `Grupo de edad_31_45` + `Grupo de edad_46_60` + `Grupo de edad_60_75` + `Grupo de edad_76+`
## 3                                                                                                                             `Elapsed time` + `Departamento o Distrito_Bogotá D.C.` + `Departamento o Distrito_Boyacá` + `Departamento o Distrito_Caldas` + `Departamento o Distrito_Casanare` + `Departamento o Distrito_Cauca` + `Departamento o Distrito_Cundinamarca` + `Departamento o Distrito_Meta` + `Departamento o Distrito_Quindío` + `Departamento o Distrito_Risaralda` + `Departamento o Distrito_Santander` + `Departamento o Distrito_Tolima`
## 4 `Elapsed time` + `Grupo de edad_19_30` + `Grupo de edad_31_45` + `Grupo de edad_46_60` + `Grupo de edad_60_75` + `Grupo de edad_76+` + `Departamento o Distrito_Bogotá D.C.` + `Departamento o Distrito_Boyacá` + `Departamento o Distrito_Caldas` + `Departamento o Distrito_Casanare` + `Departamento o Distrito_Cauca` + `Departamento o Distrito_Cundinamarca` + `Departamento o Distrito_Meta` + `Departamento o Distrito_Quindío` + `Departamento o Distrito_Risaralda` + `Departamento o Distrito_Santander` + \n    `Departamento o Distrito_Tolima`
##      theta Resid. df    2 x log-lik.   Test    df LR stat. Pr(Chi)
## 1 11252780       118       -21905.18                              
## 2 12919543       113       -20629.27 1 vs 2     5 1275.907       0
## 3 13821345       107       -19242.25 2 vs 3     6 1387.022       0
## 4 13728063       102       -18042.49 3 vs 4     5 1199.758       0

GAM

Gam with Elapsed time as covariate for Cumulative cases

## [1] "RMSE: 1282.65627040671"
## [1] "AIC: 1587.11794466718"

Gam with Elapsed time as covariate for New cases/day


## [1] "RMSE: 1121.41502755924"
## [1] "AIC: 6361.02810119354"

Gam with Elapsed time and Elapsed time^2 as covariate for Cumulative cases

## [1] "RMSE: 7633.40240922605"
## [1] "AIC: 1373.12905563382"
#intervals
se.gam1C.train<-predict(gam1C, se=TRUE, df[1:120,])$se.fit
train.lwr.gam1C<-gam1C$fitted.values - 1.96 * se.gam1C.train
train.upr.gam1C<-gam1C$fitted.values + 1.96 * se.gam1C.train

se.gam1C.test<-predict(gam1C, se=TRUE, df[120:126,])$se.fit
test.lwr.gam1C<-gam1C.pred - 1.96*se.gam1C.test
test.upr.gam1C<-gam1C.pred + 1.96*se.gam1C.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam1C, ymax = train.upr.gam1C),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam1C, ymax = test.upr.gam1C),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam1C$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam1C.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="Cumulative cases ~ Elapsed time + Elapsed time^2") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Sex as covariate for Cumulative cases

## [1] "RMSE: 2301.65489717491"
## [1] "AIC: 1525.13432986912"
#intervals
se.gam2.train<-predict(gam2, se=TRUE, df[1:120,])$se.fit
train.lwr.gam2<-gam2$fitted.values - 1.96 * se.gam2.train
train.upr.gam2<-gam2$fitted.values + 1.96 * se.gam2.train

se.gam2.test<-predict(gam2, se=TRUE, df[120:126,])$se.fit
test.lwr.gam2<-gam2.pred - 1.96*se.gam2.test
test.upr.gam2<-gam2.pred + 1.96*se.gam2.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam2, ymax = train.upr.gam2),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam2, ymax = test.upr.gam2),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam2$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam2.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="Cumulative cases ~ Elapsed time + Sex") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Age as covariate for Cumulative cases

## [1] "RMSE: 3874.19862207912"
## [1] "AIC: 1519.73391196235"
#intervals
se.gam3.train<-predict(gam3, se=TRUE, df[1:120,])$se.fit
train.lwr.gam3<-gam3$fitted.values - 1.96 * se.gam3.train
train.upr.gam3<-gam3$fitted.values + 1.96 * se.gam3.train

se.gam3.test<-predict(gam3, se=TRUE, df[120:126,])$se.fit
test.lwr.gam3<-gam3.pred - 1.96*se.gam3.test
test.upr.gam3<-gam3.pred + 1.96*se.gam3.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam3, ymax = train.upr.gam3),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam3, ymax = test.upr.gam3),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam3$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam3.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="Cumulative cases ~ Elapsed time + Age group") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Department as covariate for Cumulative cases

## [1] "RMSE: 1808.40316728465"
## [1] "AIC: 1486.02139832832"
#intervals
se.gam4.train<-predict(gam4, se=TRUE, df[1:120,])$se.fit
train.lwr.gam4<-gam4$fitted.values - 1.96 * se.gam4.train
train.upr.gam4<-gam4$fitted.values + 1.96 * se.gam4.train

se.gam4.test<-predict(gam4, se=TRUE, df[120:126,])$se.fit
test.lwr.gam4<-gam4.pred - 1.96*se.gam4.test
test.upr.gam4<-gam4.pred + 1.96*se.gam4.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam4, ymax = train.upr.gam4),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam4, ymax = test.upr.gam4),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam4$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam4.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="Cumulative cases ~ Elapsed time + Department") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Department and Age as covariate for Cumulative cases

## [1] "RMSE: 1038.67068102764"
## [1] "AIC: 1486.7078613768"
#intervals
se.gam5.train<-predict(gam5, se=TRUE, df[1:120,])$se.fit
train.lwr.gam5<-gam5$fitted.values - 1.96 * se.gam5.train
train.upr.gam5<-gam5$fitted.values + 1.96 * se.gam5.train

se.gam5.test<-predict(gam5, se=TRUE, df[120:126,])$se.fit
test.lwr.gam5<-gam5.pred - 1.96*se.gam5.test
test.upr.gam5<-gam5.pred + 1.96*se.gam5.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam5, ymax = train.upr.gam5),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam5, ymax = test.upr.gam5),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam5$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam5.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="Cumulative cases ~ Elapsed time + Department + Age group") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Department and Age as covariate for New cases/day

## [1] "RMSE: 868.400823217958"
## [1] "AIC: 1078.02668310693"
#intervals
se.gam5bis.train<-predict(gam5bis, se=TRUE, df[1:120,])$se.fit
train.lwr.gam5bis<-gam5bis$fitted.values - 1.96 * se.gam5bis.train
train.upr.gam5bis<-gam5bis$fitted.values + 1.96 * se.gam5bis.train

se.gam5bis.test<-predict(gam5bis, se=TRUE, df[120:126,])$se.fit
test.lwr.gam5bis<-gam5bis.pred - 1.96*se.gam5bis.test
test.upr.gam5bis<-gam5bis.pred + 1.96*se.gam5bis.test

ggplot(df, aes(Elapsed_time, New_cases_day)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam5bis, ymax = train.upr.gam5bis),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam5bis, ymax = test.upr.gam5bis),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam5bis$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam5bis.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = New_cases_day)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="New cases/day ~ Elapsed time + Department + Age group") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Gam with Elapsed time and Elapsed time^2 and Department and Age as covariate for Cumulative cases

## [1] "RMSE: 4599.76893593702"
## [1] "AIC: 1337.16765230381"
#intervals
se.gam6.train<-predict(gam6, se=TRUE, df[1:120,])$se.fit
train.lwr.gam6<-gam6$fitted.values - 1.96 * se.gam6.train
train.upr.gam6<-gam6$fitted.values + 1.96 * se.gam6.train

se.gam6.test<-predict(gam6, se=TRUE, df[120:126,])$se.fit
test.lwr.gam6<-gam6.pred - 1.96*se.gam6.test
test.upr.gam6<-gam6.pred + 1.96*se.gam6.test

ggplot(df, aes(Elapsed_time, Cumulative_cases)) +
  geom_ribbon(aes(x = Elapsed_time, ymin = train.lwr.gam6, ymax = train.upr.gam6),
              data = df[1:120, ],
              fill = color_scheme_get("blue")[[2]]) + 
  geom_ribbon(aes(x = Elapsed_time, ymin = test.lwr.gam6, ymax = test.upr.gam6),
              data = df[120:126, ],
              fill = color_scheme_get("red")[[2]]) +
  geom_line(aes(x = Elapsed_time, y = gam6$fitted.values),
              data = df[1:120, ],
              color = color_scheme_get("blue")[[4]], 
              size = 1.1) +
  geom_line(aes(x= Elapsed_time, y = gam6.pred),
              data = df[120:126, ],
              color = color_scheme_get("red")[[4]],
              size = 1.1) +
  geom_point(aes(x = Elapsed_time, y = Cumulative_cases)) +
  expand_limits(x = 28) +
  ggtitle("GAM Model", subtitle="New cases/day ~ Elapsed time + Elapsed time^2 + Department + Age") +
  xlab("Days") + ylab("Total cases") +
  scale_x_discrete(limit = c(0, 21, 42, 63, 84, 105, 122, 128),
                labels = c("06-3", "29-3", "19-4", "10-5", "31-5", "21-6", "06-7", "12-7")) +
  # facet_wrap(~"Department", scales ='free') +
  theme(strip.text.x = element_text(size = 12, colour = "black"),
        axis.text.x = element_text(face = "bold",
        color = "#993333", angle = 45, size = 9),
        plot.title = element_text(size = 22),
        axis.title.x = element_text(size = 18), 
        axis.title.y = element_text(size = 18))

Summary table - GAM models for Cumulative cases

Model AIC RMSE
Cumulative cases ~ Elapsed time 1587 1282
Cumulative cases ~ Elapsed time + Elapsed time^2 1373 7633
Cumulative cases ~ Elapsed time + Sex 1525 2301
Cumulative cases ~ Elapsed time + Age group 1519 3874
Cumulative cases ~ Elapsed time + Department 1486 1808
Cumulative cases ~ Elapsed time + Department + Age group 1486 1038
Cumulative cases ~ Elapsed time + Elapsed time^2 + Department + Age group 1337 4599

Summary table - GAM models for New cases/day

Model AIC RMSE
New cases/day ~ Elapsed time 6361 1121
New cases/day ~ Elapsed time + Age group + Department 1078 2868

The Bayesian approach

Poisson regression for response variable Cumulative cases/Department

As a first attempt, we fit a simple Poisson regression: \[ ln(\lambda_i) = \alpha + \beta\cdot elapsed\_time_i \\ y_i \sim \mathcal{Poisson}(\lambda_i) \\ \alpha \sim \mathcal{N}(0,1) \\ \beta \sim \mathcal{N}(0.25,1) \] with \(i = 1,\dots,134\), being \(134\) the number of rows of our dataset, and \(y_i\) represents the number of cases.

For what concerns the stan program, we used the function poisson_log_rng to describe the distribution of \(y_i\), namely the number of cases each day and the function poisson_log_lpmf to specify the likelihood.

Posterior predictive check - Poisson Cumulative cases/Department

poisson_cumulative

The fit is not satisfactory, it is probably due to overdispersion, we can check the residuals to confirm this hypothesis.

poisson_cumulative_ecdf

Residual check - Poisson Cumulative cases/Department

poisson_cumulative_res

The variance of the residuals increases as the predicted value increase. The standardized residuals should have mean 0 and standard deviation 1 (hence the lines at \(+2\) and \(-2\) indicates approximate \(95\%\) error bounds).

The plot of the standardized residuals indicates a large amount of overdispersion.

Intervals - Poisson Cumulative cases/Department

poisson_cumulative_intervals

Accuracy - Poisson Cumulative cases/Department

poisson_cumulative_acc

Negative Binomial model for Cumulative cases /Department

We try to improve the previous model using the Negative Binomial model:

\[ ln(\lambda_i) = \alpha + \beta\cdot elapsed\_time_i \\ y_i \sim \mathcal{Negative Binomial}(\lambda_i, \phi) \\ \alpha \sim \mathcal{N}(0,1) \\ \beta \sim \mathcal{N}(0.25,1) \]

Where the parameter \(\phi\) is called precision and it is such that:

\[ E[y_i] = \lambda_i \\ Var[y_i] = \lambda_i + \frac{\lambda_i^2}{\phi} \]

again \(i=1,\dots,134\). As \(\phi \rightarrow \infty\) the negative binomial approaches the Poisson distribution.

The stan function that we use here are neg_binomial_2_log_rng to specify the distribution of \(y_i\) and the function neg_binomial_2_log_lpmf for the likelihood.

Residual check - NB Cumulative cases /Department

NB_cumulative_res

The situation is better now, but still we have too many residuals outside the \(95\%\) interval.

Accuracy across departments - NB Cumulative cases /Department

NB_cumulative_acc

We should take into account the differences across departments.

Negative Binomial model for New cases/day

Multilevel Negative Binomial regression for Cumulative/Department

We try to fit the following model, which also includes Age as covariat:

\[ ln(\lambda_i) = \alpha + \beta_{time}\cdot elapsed\_time_i + \beta_{age}\cdot age \\ y_i \sim \mathcal{Negative Binomial}(\lambda_i, \phi) \\ \alpha \sim \mathcal{N}(0,1) \\ \beta_{time} \sim \mathcal{N}(0.5,1) \\ \beta_{age} \sim \mathcal{N}(0,1) \]

Hierarchical model for Cumulative/Department

In order to improve the fit, we fit a model with department-specific intercept term.

So the varying intercept model that we take into account is now:

\[ ln(\lambda_{i,d}) = \alpha_d + + \beta_{time}\cdot elapsed\_time_i + \beta_{age}\cdot age_i\\ \alpha_d \sim \mathcal{N}(\mu + \beta_{pop}\cdot pop_d + \beta_{sur}\cdot surface_d + \beta_{dens} \cdot density_d, \sigma_{\alpha})\\ y_i \sim \mathcal{Negative Binomial}(\lambda_{i,d}, \phi) \]

The priors used for the above model are the following:

\[ \beta_{time} \sim \mathcal{N}(0.5,1) \\ \beta_{age} \sim \mathcal{N}(0,1) \\ \psi \sim \mathcal{N}(0,1) \]

being \(\psi = [\beta_{pop}, \beta_{sur}, \beta_{dens}]\).

New dataset

We added the following covariats into the dataset:

  • People: millions of inhabitants for each region;

    • Surface: \(km^3\), extent of each region;

    • Density: \(\frac{people}{km^2}\), density of the population in each region.

The model is:

Accuracy across departments - hierarchical NB Cumulative/Department

hier_cumulative_acc

We can clearly see that the accuracy across the departments has significantly increased with respect to the previous models.

LOOIC

The Leave-One-Out cross validation is a method for estimating pointwise out-of-sample prediction accuracy from a fitted Bayesian model using the log-likelihood evaluated at the posterior simulation of the parameters values.

Plot the looic to compare models:

looic